package demo.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import demo.model.User;

import javax.servlet.http.HttpSession;

public class DemoInterceptor implements Interceptor {
    public void intercept(Invocation inv) {
        HttpSession httpSession = inv.getController().getSession();
        User user = (User) httpSession.getAttribute("user");
        System.out.println(user);
        if (user == null) {
            inv.getController().redirect("/login");
        } else {
            inv.invoke();
        }
    }
}
